#这里按实际情况修改
echo "--------修改hosts--------"
cat <<EOF >>/etc/hosts
10.100.79.221 node-b
10.100.79.220 node-a
10.100.79.222 node-c
EOF

systemctl restart network
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kube*
EOF


#docker环境自行安装，记得修改daemon配置，增加2375管理端口暴露，修改后重启docker

systemctl disable firewalld
systemctl stop firewalld

#关闭swap
swapoff -a
#修改/etc/fstab中内容，将swap哪一行用#注释掉
sed -i 's/.*swap.*/#&/' /etc/fstab

# Set SELinux in permissive mode (effectively disabling it)
# 将 SELinux 设置为 permissive 模式(将其禁用)
setenforce 0
sed -i 's/^SELINUX=.*$/SELINUX=permissive/' /etc/selinux/config


yum install -y kubelet-1.17.4 kubeadm-1.17.4 kubectl-1.17.4 --disableexcludes=kubernetes

systemctl enable kubelet && systemctl start kubelet

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
echo "1" > /proc/sys/net/ipv4/ip_forward


# 下载k8s.1.17.4所需要的镜像列表
echo 'docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.17.4
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1

docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:v1.17.4 k8s.gcr.io/kube-proxy:v1.17.4' > ~/down-images.sh

chmod +777 ~/down-images.sh
sh ~/down-images.sh

#修改默认的master/node网卡ip，如果是虚机有多块网卡，可以指定用哪个ip(eth1可以改为你自己想绑定的网卡名称)
echo KUBELET_EXTRA_ARGS=\"--node-ip=`ip addr show eth1 | grep inet | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}/" | tr -d '/'`\" > /etc/sysconfig/kubelet
systemctl daemon-reload
systemctl restart kubelet

# 执行节点加入操作
# 示例： kubeadm join 10.100.79.220:6443 --token jrk73b.m6ly1m4pz5g7ymbm --discovery-token-ca-cert-hash sha256:18c361e1e5031ab1fb0c195b3dff6b2f3557c98db621cf34077afe66845e40ab
# 下面的join_token要替换与具体的主节点的token , 主节点执行命令：kubeadm token list 查看可用的token列表，主节点创建新token命令：kubeadm token create
kubeadm join 10.100.79.220:6443 --token xuutbj.ul9tn5be8vhjdokb \
    --discovery-token-ca-cert-hash sha256:4bf34dec8bfb2e02f7382d2f3466a2e08bbf8a5d828834f537eddf20f55db9a6
